package com.orangelife.mobile.parkingfee.activity;

import java.util.HashMap;
import java.util.Map;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.curry.android.util.StringUtil;
import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.app.application.ExitApplication;
import com.orangelife.mobile.common.activity.OrangeLifeBaseActivity;
import com.orangelife.mobile.confirmOrder.activity.PayConfirmOrderActivity;
import com.orangelife.mobile.util.EditTextInputUtil;
import com.orangelife.mobile.util.ToastHelper;
import com.orangelife.mobile.zoning.activity.SelectCommunityActivity;
import com.orangelife.mobile.zoning.activity.SelectFloorActivity;
import com.orangelife.mobile.zoning.activity.SelectHousesActivity;
import com.orangelife.mobile.zoning.activity.SelectParkinglotActivity;
import com.orangelife.mobile.zoning.activity.SelectZoningActicity;

/**
 * 停车费管家
 * @author lxj
 *
 */
@Deprecated
public class ParkingFeeActivity extends OrangeLifeBaseActivity {

	/** 省市区车位号编辑框 */
	private TextView tvProvince, tvfloor, tvComm, tvHouses, tvParkingLot;
	/** 车牌号、缴费金额编辑框 */
	private EditText etLicensePlate, etPayment;
	/** 业主验证提交按钮 */
	private Button btnNext;
	/** 标题 */
	private TextView tvTitle, tvTitleRight;
	private String mprovince=null;
	private String mcity=null;
	private String mdistrict=null;
	private RelativeLayout zoning, comm, floor, houses, parkinglot;
	private String commID, commName=null;
	private String apartmentName, apartmentID;
	private String buildingName, buildingID;
	private String parkinglotName, parkinglotID;
	
	/** 设置提示的信息 */
	private TextView tvComName;
	public static String BUILDINGID;
	private Dialog dialog;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_parking_fee);

		initeView();
		findView();
	}

	/** 初始化控件 */
	private void initeView() {
		tvProvince = (TextView)findViewById(R.id.et_province);
		tvfloor= (TextView)findViewById(R.id.et_floor);
		tvComm= (TextView)findViewById(R.id.et_comm);
		tvHouses= (TextView)findViewById(R.id.tv_houses_num);
		tvParkingLot = (TextView)findViewById(R.id.tv_parkinglot);
		etLicensePlate = (EditText)findViewById(R.id.et_license_plate);
		etPayment = (EditText)findViewById(R.id.et_payment);
		btnNext = (Button) findViewById(R.id.btn_submit);
		tvTitle = (TextView) findViewById(R.id.tv_title);
		tvTitleRight = (TextView) findViewById(R.id.tv_title_right);
		zoning = (RelativeLayout)findViewById(R.id.ll_zoning);
		comm = (RelativeLayout)findViewById(R.id.ll_comm);
		floor = (RelativeLayout)findViewById(R.id.ll_floor);
		houses = (RelativeLayout)findViewById(R.id.ll_houses);
		parkinglot = (RelativeLayout)findViewById(R.id.ll_parkinglot);
	}

	public void hideInput(View v) {
		InputMethodManager imm = (InputMethodManager) this
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		// edit.setCursorVisible(false);//失去光标
		imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
	}

	/** 设置控件的值或状态 */
	private void findView() {
		tvTitle.setText(getResources().getString(R.string.parking_fee_management));
		
		HashMap<String, Object> parkingMap = new HashMap<String, Object>();
//		if (!StringUtil.isContainBlank(.getParkingFeeInfo()
//				.get("province").toString())) {
//			tvProvince.setText(parkingMap.get("province").toString());
//			tvComm.setText(parkingMap.get("community").toString());
//			tvfloor.setText(parkingMap.get("building").toString());
//			tvHouses.setText(parkingMap.get("house").toString());
//			tvParkingLot.setText(parkingMap.get("parkinglot").toString());
//			etLicensePlate.setText(parkingMap.get("license").toString());
//			mcity = parkingMap.get("mcity").toString();
//			commID = parkingMap.get("commID").toString();
//			buildingID = parkingMap.get("buildingID").toString();
//			apartmentID = parkingMap.get("apartmentID").toString();
//		}
		
		zoning.setOnClickListener(listener);
		comm.setOnClickListener(listener);
		floor.setOnClickListener(listener);
		houses.setOnClickListener(listener);
		parkinglot.setOnClickListener(listener);
		btnNext.setOnClickListener(listener);
		tvTitleRight.setVisibility(View.INVISIBLE);
		EditTextInputUtil.setPricePoint(etPayment);
	}

	



	/** 定义监听器 */
	private OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(View view) {
			Intent intent=null;
			switch (view.getId()) {
			case R.id.ll_zoning:
				intent=new Intent();
				intent.setClass(ParkingFeeActivity.this, SelectZoningActicity.class);
				startActivityForResult(intent,1);
				break;
			case R.id.ll_comm:
				if(StringUtil.isContainBlank(tvProvince.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择城市");
				}else{
					intent=new Intent();
					intent.setClass(ParkingFeeActivity.this, SelectCommunityActivity.class);
					intent.putExtra("cityName", mcity);
					startActivityForResult(intent,6);
				}
				break;
			case R.id.ll_floor:
				if(StringUtil.isContainBlank(tvProvince.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择城市");
				} else if(StringUtil.isContainBlank(tvComm.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择小区");
				} else{
					intent=new Intent();
					intent.setClass(ParkingFeeActivity.this, SelectFloorActivity.class);
					intent.putExtra("comID", commID);
					startActivityForResult(intent,7);
				}
				break;
			case R.id.ll_houses:
				if(StringUtil.isContainBlank(tvProvince.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择城市");
				} else if(StringUtil.isContainBlank(tvComm.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择小区");
				} else if(StringUtil.isContainBlank(tvfloor.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择楼栋");
				} else {
					intent=new Intent();
					intent.setClass(ParkingFeeActivity.this, SelectHousesActivity.class);
					intent.putExtra("buildingID", buildingID);
					startActivityForResult(intent,8);
				}
				break;
			case R.id.ll_parkinglot:
				if(StringUtil.isContainBlank(tvProvince.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择城市");
				} else if(StringUtil.isContainBlank(tvComm.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择小区");
				} else if(StringUtil.isContainBlank(tvfloor.getText().toString())){
					ToastHelper.getInstance()._toast("请先选择楼栋");
				} else if(StringUtil.isContainBlank(tvHouses.getText().toString())) {
					ToastHelper.getInstance()._toast("请先选择房号");
				} else {
					intent=new Intent();
					intent.setClass(ParkingFeeActivity.this, SelectParkinglotActivity.class);
					intent.putExtra("apartmentID", apartmentID);
					startActivityForResult(intent,9);
				}
				break;
			case R.id.btn_submit:
				if(StringUtil.isContainBlank(tvProvince.getText().toString())) {
					ToastHelper.getInstance()._toast("城市不能为空");
				} else if(StringUtil.isContainBlank(tvComm.getText().toString())) {
					ToastHelper.getInstance()._toast("小区不能为空");
				} else if(StringUtil.isContainBlank(tvComm.getText().toString())) {
					ToastHelper.getInstance()._toast("小区不能为空");
				} else if(StringUtil.isContainBlank(tvfloor.getText().toString())) {
					ToastHelper.getInstance()._toast("楼栋不能为空");
				} else if(StringUtil.isContainBlank(tvHouses.getText().toString())) {
					ToastHelper.getInstance()._toast("房号不能为空");
				} else if(StringUtil.isContainBlank(tvParkingLot.getText().toString())) {
					ToastHelper.getInstance()._toast("车位号不能为空");
				} else if(StringUtil.isContainBlank(etLicensePlate.getText().toString())) {
					ToastHelper.getInstance()._toast("车牌号不能为空");
				}
				else
				{
					if(!StringUtil.isPlate(etLicensePlate.getText().toString())){
						ToastHelper.getInstance()._toast("车牌号格式错误");
					}
					else if(StringUtil.isContainBlank(etPayment.getText().toString())) {
						   ToastHelper.getInstance()._toast("缴费金额不能为空");
					    } else if((!etPayment.getText().toString().equals("0"))&&
								  (!etPayment.getText().toString().equals("0.0"))&&
								  (!etPayment.getText().toString().equals("0.00"))){
//						HashMap<String, Object> map1 = new HashMap<String, Object>();
//						map1.put("province", tvProvince.getText().toString());
//						map1.put("community", tvComm.getText().toString());
//						map1.put("building", tvfloor.getText().toString());
//						map1.put("house", tvHouses.getText().toString());
//						map1.put("parkinglot", tvParkingLot.getText().toString());
//						map1.put("license", etLicensePlate.getText().toString());
//						map1.put("mcity", mcity);
//						map1.put("commID", commID);
//						map1.put("buildingID", buildingID);
//						map1.put("apartmentID", apartmentID);
//						.setParkingFeeInfo(map1);
						ExitApplication.getInstance().addPaidActivity(ParkingFeeActivity.this);
						Intent data = new Intent();
						data.putExtra("City", tvProvince.getText().toString());
						data.putExtra("Comm", tvComm.getText().toString());
						data.putExtra("Floor", tvfloor.getText().toString());
						data.putExtra("House", tvHouses.getText().toString());
						data.putExtra("ParkingLot", tvParkingLot.getText().toString());
						data.putExtra("LicensePlate", etLicensePlate.getText().toString());
						data.putExtra("Payment", etPayment.getText().toString());
						data.putExtra("apartmentID", apartmentID);
						data.putExtra("parkID", parkinglotID);
						data.putExtra("type",4);
						data.setClass(ParkingFeeActivity.this, PayConfirmOrderActivity.class);
						startActivity(data);
					}else{
						ToastHelper.getInstance()._toast("缴费金额不能为零");
					}
				}
				break;
			default:
				break;
			}
			
		}
	};


	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case 1:
			if(data!=null){
				Map<String,Object> map = (Map<String, Object>) data.getSerializableExtra("zoning");
				mprovince=map.get("province").toString();
				if(!(map.get("city").toString().equals(mcity))){
					tvComm.setText("");
					tvfloor.setText("");
					tvHouses.setText("");
					tvParkingLot.setText("");
				}
				mcity=map.get("city").toString();
				mdistrict=map.get("district").toString();
				tvProvince.setText(mprovince+mcity+mdistrict);
			}
			break;
		case 7:
			if(data!=null){
				if(!(data.getStringExtra("buildingID").equals(buildingID))){
					tvHouses.setText("");
					tvParkingLot.setText("");
				}
				buildingName=data.getStringExtra("buildingName");
				buildingID=data.getStringExtra("buildingID");
				tvfloor.setText(buildingName);
			}
			break;
		case 6:
			if(data!=null){
				if(!(data.getStringExtra("commID").equals(commID))){
					tvfloor.setText("");
					tvHouses.setText("");
					tvParkingLot.setText("");
				}
				commID=data.getStringExtra("commID");
				commName=data.getStringExtra("comm");
				tvComm.setText(commName);
			}
			break;
		case 8:
			if(data!=null){
				if(!(data.getStringExtra("apartmentID").equals(apartmentID))){
					tvParkingLot.setText("");
				}
				apartmentID=data.getStringExtra("apartmentID");
				apartmentName=data.getStringExtra("apartmentName");
				tvHouses.setText(apartmentName);
			}
			break;
		case 9:
			if(data!=null){
				parkinglotID=data.getStringExtra("parkinglotID");
				parkinglotName=data.getStringExtra("parkinglotName");
				tvParkingLot.setText(parkinglotName);
			}
			break;
		default:
		}
	}
	
}
